home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / dosmesa.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-02  |  31.8 KB  |  1,486 lines

  1. /* $Id: dosmesa.c 1.2 1996/12/08 16:13:45 Charlie Exp Charlie $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.0
  6.  * Copyright (C) 1995-1996  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: dosmesa.c $
  26.  * Revision 1.2  1996/12/08  16:13:45  Charlie
  27.  * Added VESA support via Scitechs SVGA kit.
  28.  *
  29.  * Revision 1.1  1996/12/08  16:09:52  Charlie
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34.  
  35. /*
  36.  * DOS VGA/VESA/MGL/Mesa interface.
  37.  *
  38.  */
  39.  
  40. /*
  41.  *
  42.  * TODO: (cw)
  43.  *     Improve the colour matcher for rgb non vesa modes, its pretty bad and incorrect
  44.  *     Keyboard interrupt.
  45.  *  Comments and tidy up.
  46.  *  Add support for VESA without SVGAKIT.
  47.  *  DirectX Support.
  48.  *  Better GLIDE Support.
  49.  *  Clear up the #ifdef madness.
  50.  */
  51.  
  52. #ifdef DOSVGA
  53.  
  54. #if defined(DOSVGA) && !defined(GLIDE) && !defined(DJGPP) && !defined(UNIVBE) && !defined(MGL)
  55.  
  56. /* Should help cut down on the crazy #if`s */
  57. #define MODE13 1
  58.  
  59. #else
  60. #undef MODE13
  61. #endif
  62.  
  63. #include <stdio.h>
  64. #include <stdlib.h>
  65. #include <string.h>
  66. #include <string.h>
  67. #include <dos.h>
  68.  
  69. #ifdef DJGPP
  70. #include <go32.h>
  71. #endif
  72.  
  73. #ifdef MGL
  74. #include <mgraph.h>
  75. #endif
  76.  
  77. #include "GL/DOSmesa.h"
  78. #include "context.h"
  79. #include "matrix.h"
  80. #include "types.h"
  81.  
  82. #ifdef GLIDE
  83.  
  84. static void glideshutdown( void );
  85. #include "vb.h"
  86. #include "glide.h"
  87.  
  88. /* the glide modes available, set one */
  89.  
  90. //#define GLIDE_MODE GR_RESOLUTION_
  91. #define GLIDE_MODE GR_RESOLUTION_800x600
  92. //#define GLIDE_MODE GR_RESOLUTION_640x480
  93.  
  94. static GrVertex gr_vtx,gr_vtx1,gr_vtx2;
  95.  
  96. #endif
  97.  
  98. #ifdef UNIVBE
  99. /* You get this file from Scitechs VESA development kit */
  100. #include "svga.h"
  101.  
  102. /*
  103.    Set these to the VESA mode you require, the first is for 256 colour modes,
  104.    the other is High colour modes, they must both be the same XRes and YRes.
  105.  */
  106.  
  107. #define VESA_256COLOUR_MODE 0x11c
  108. #define VESA_HICOLOUR_MODE 0x11f
  109.  
  110. #endif
  111.  
  112. struct DOSmesa_context {
  113.    GLcontext *gl_ctx;            /* the core Mesa context */
  114.    GLvisual *gl_vis;                /* describes the color buffer */
  115.    GLframebuffer *gl_buffer;    /* the ancillary buffers */
  116.    GLuint index;                    /* current color index */
  117.    GLint red, green, blue;        /* current rgb color */
  118.    GLint width, height;            /* size of color buffer */
  119.    GLint depth;                    /* bits per pixel (8,16,24 or 32) */
  120. };
  121.  
  122. static DOSMesaContext DOSMesa = NULL;    /* the current context */
  123.  
  124. #ifdef UNIVBE
  125. SV_devCtx *DC=NULL;
  126. int useLinear = TRUE;
  127. SV_modeInfo *mi=NULL;
  128. unsigned long modeNumber = 0;
  129.  
  130. int activePage = 0;
  131. int visualPage = 1;
  132.  
  133. #endif
  134.  
  135. #if defined(MODE13)
  136.  
  137. /* DOSVGA With no UniVBE support */
  138.  
  139. unsigned char *video_buffer = (unsigned char *)0xa0000;
  140.  
  141. #define VID_BUF(x,y) *(video_buffer+x+(y*320))
  142.  
  143. #if defined(__WATCOMC__) && defined(__386__) && defined(__DOS__)
  144.  
  145. void setupcopy(void);
  146. void copyscr(void);
  147.  
  148. /* Watcom C specfic, screen copy and clear */
  149.  
  150. #pragma aux setupcopy = \
  151.     ".386P"\
  152.     "push ebp" \
  153.     "mov esi,video_buffer" \
  154.     "mov edi,0xa0000" \
  155.     "mov ecx,2000" \
  156.     "xor ebp,ebp";
  157.  
  158. #pragma aux copyscr = \
  159.     ".386P" \
  160.     "lop1: mov eax,[esi]"\
  161.     "mov ebx,[esi+4]"\
  162.     "mov edx,[esi+8]"\
  163.     "mov [edi],eax"\
  164.     "mov eax,[esi+12]"\
  165.     "mov dword ptr [esi],ebp"\
  166.     "mov dword ptr [esi+4],ebp"\
  167.     "mov dword ptr [esi+8],ebp"\
  168.     "mov dword ptr [esi+12],ebp"\
  169.     "mov [edi+4],ebx"\
  170.     "mov [edi+8],edx"\
  171.     "mov [edi+12],eax"\
  172.     "mov eax,[esi+16]"\
  173.     "mov ebx,[esi+4+16]"\
  174.     "mov edx,[esi+8+16]"\
  175.     "mov [edi+16],eax"\
  176.     "mov eax,[esi+12+16]"\
  177.     "mov dword ptr [esi+16],ebp"\
  178.     "mov dword ptr [esi+4+16],ebp"\
  179.     "mov dword ptr [esi+8+16],ebp"\
  180.     "mov dword ptr [esi+12+16],ebp"\
  181.     "mov [edi+4+16],ebx"\
  182.     "mov [edi+8+16],edx"\
  183.     "mov [edi+12+16],eax"\
  184.     "add esi,32"\
  185.     "add edi,32"\
  186.     "dec ecx"\
  187.     "jnz lop1"\
  188.     "pop ebp"\
  189.     modify exact [edi esi eax ebx ecx] ;
  190.  
  191. #endif // WATCOM
  192.  
  193. #endif // MODE13
  194.  
  195. /*
  196.  * Convert Mesa window Y coordinate to VGA screen Y coordinate:
  197.  */
  198. #define FLIP(Y)  (DOSMesa->height-(Y)-1)
  199.  
  200. unsigned short vga_cindex = 32768 ;
  201.  
  202. static points_func choose_points_function( void );
  203. static line_func choose_line_function( void );
  204. static triangle_func choose_polygon_function( void );
  205. static void fast_tri(GLcontext *ctx,GLuint v0, GLuint v1, GLuint v2, GLuint pv );
  206.  
  207. static points_func choose_points_function( void )
  208. {
  209.     return NULL;
  210. }
  211.  
  212. static line_func choose_line_function( void )
  213. {
  214.     return NULL;
  215. }
  216.  
  217. static triangle_func choose_triangle_function( void )
  218. {
  219.     #if defined(MODE13)
  220.         return    NULL;
  221.     #endif
  222.  
  223.     #if defined(GLIDE)
  224.         return fast_tri;
  225.     #endif
  226.  
  227.     return    NULL;
  228. }
  229.  
  230.  
  231. #if defined(MODE13)
  232.  
  233. void setgfxmode(void);
  234. void settextmode(void);
  235.  
  236. #ifndef DJGPP
  237. #pragma aux setgfxmode = \
  238.     "mov    ax,13h" \
  239.     "int    10h" \
  240.     modify [eax];
  241.  
  242. #pragma aux settextmode = \
  243.     "mov    ax,3h" \
  244.     "int    10h" \
  245.     modify [eax];
  246. #else
  247. void setgfxmode(void)
  248. {
  249.     union REGS in_regs,out_regs;
  250.  
  251.     in_regs.x.ax = 0x13;
  252.     int386(0x10,&in_regs,&out_regs);
  253. }
  254.  
  255. void settextmode(void)
  256. {
  257.     union REGS in_regs,out_regs;
  258.  
  259.     in_regs.x.ax = 0x3;
  260.     int386(0x10,&in_regs,&out_regs);
  261. }
  262.  
  263. #endif
  264.  
  265. int set_video_mode(unsigned short x,unsigned short y,char mode)
  266. {
  267.     setgfxmode();
  268.     return 1;    /* likelyhood of this failing is very small */
  269. }
  270.  
  271. void restore_video_mode(void)
  272. {
  273.     settextmode();
  274. }
  275.  
  276. int vga_getcolors(void)
  277. {
  278.     return vga_cindex;
  279. }
  280.  
  281. int vga_getxdim(void)
  282. {
  283.     return 320;
  284. }
  285.  
  286. int vga_getydim(void)
  287. {
  288.     return 200;
  289. }
  290.  
  291. static unsigned short num_rgb_alloc = 1; /* start from 1, zero is black */
  292.  
  293. /* an unlikely colour */
  294. static unsigned char last_r=1,last_g=255,last_b=99;
  295.  
  296. extern void set_onecolor(int index,int R,int G,int B);
  297.  
  298. static unsigned char rgbtable[64][64][64];
  299.  
  300. void vga_setrgbcolor(int r,int g,int b)
  301. {
  302.  
  303. /*
  304.  * make this into a translation table
  305.  */
  306.  
  307.     DOSMesa->red = r;
  308.     DOSMesa->green = g ;
  309.     DOSMesa->blue = b ;
  310.  
  311.     r/=4; g/=4; b/=4;
  312.  
  313.     if( (r == last_r) && (g == last_g) && (b == last_b) ) return;
  314.  
  315.     last_r = r ;
  316.     last_g = g ;
  317.     last_b = b ;
  318.  
  319.     if(r+g+b == 0 ) {
  320.         DOSMesa->index = 0 ;
  321.         return ;
  322.     }
  323.  
  324.     if( rgbtable[r][g][b] == 0 ) {
  325.         /* not allocated yet */
  326.         if(num_rgb_alloc<256) {
  327.             DOSMesa->index = num_rgb_alloc;
  328.             set_onecolor(num_rgb_alloc,r,g,b);
  329.             rgbtable[r][g][b] = num_rgb_alloc;
  330.             num_rgb_alloc++;
  331.             return;
  332.  
  333.         } else {
  334.             /* need to search for a close colour */
  335.             {
  336.                 unsigned short pass ;
  337.  
  338.                 for(pass=0;pass<64;pass++) {
  339.                     if(r-pass>0) {
  340.                         if( rgbtable[r-pass][g][b] !=0 ) {
  341.                             rgbtable[r][g][b] = rgbtable[r-pass][g][b];
  342.                             DOSMesa->index = rgbtable[r-pass][g][b];
  343.                             return;
  344.                         }
  345.                     }
  346.                     if(r+pass<64) {
  347.                         if( rgbtable[r+pass][g][b] !=0 ) {
  348.                             rgbtable[r][g][b] = rgbtable[r+pass][g][b];
  349.                             DOSMesa->index = rgbtable[r+pass][g][b];
  350.                             return;
  351.                         }
  352.                     }
  353.                 }
  354.             }
  355.             rgbtable[r][g][b] = rand()%255;
  356.         }
  357.     }
  358.     DOSMesa->index = rgbtable[r][g][b];
  359. }
  360.  
  361. #if defined(DJGPP)
  362. static int dos_seg;
  363. #endif
  364.  
  365. void vga_clear(void)
  366. {
  367.  
  368. /* Check if we`re using watcom and DOS */
  369. #if defined(__WATCOMC__) && defined(__386__) && defined(__DOS__)
  370.     setupcopy();
  371.     copyscr();
  372. #else
  373.  
  374. #if !defined(UNIVBE) && defined (DJGPP) && !defined(GLIDE)
  375.  
  376.  
  377.     asm ("
  378.         pusha
  379.         pushw    %es
  380.  
  381.         movw    _dos_seg, %es
  382.  
  383.         movl    _video_buffer, %esi
  384.         movl    $0xa0000, %edi
  385.  
  386.         movl    $64000, %ecx
  387.  
  388.         rep    ; movsb
  389.  
  390.         popw    %es
  391.         popa
  392.     ");
  393.  
  394. #endif
  395.  
  396. #if defined(MODE13)
  397.     /* copy the RAM buffer to the Video memory */
  398.     memcpy((unsigned char *)0xa0000,video_buffer, vga_getxdim()*vga_getydim() );
  399. #endif
  400.  
  401. #if defined(DJGPP)
  402.     /* clear the RAM buffer */
  403.     memset(video_buffer,0, vga_getxdim()*vga_getydim() );
  404. #endif
  405.  
  406. #endif
  407.  
  408. }
  409.  
  410. #ifndef DEBUG
  411. #define vga_drawpixel(x,y) { VID_BUF(x,y) = DOSMesa->index; }
  412. #else
  413. void vga_drawpixel(x,y)
  414. {
  415.     VID_BUF(x,y) = DOSMesa->index;
  416. }
  417. #endif
  418.  
  419. int vga_getpixel(int x,int y)
  420. {
  421.     return 1;
  422. }
  423.  
  424. void vga_flip(void)
  425. {
  426.  
  427. }
  428.  
  429. void vga_setcolor(int index)
  430. {
  431.     /* does something, what i`ve no idea */
  432.     DOSMesa->index = index;
  433.  
  434. }
  435.  
  436. #endif
  437.  
  438. #if defined(UNIVBE)
  439.  
  440. /* UniVBE VESA support */
  441.  
  442. void set_video_mode(unsigned short x,unsigned short y,char mode)
  443. {
  444.     if( setup_vesa_mode(x,y,mode) == FALSE ) {
  445.         fprintf(stderr,"VESA: Set mode failed\n");
  446.         exit(1);
  447.     }
  448. }
  449.  
  450. /*
  451.    This is problematic as we don`t know what resolution the user program
  452.    wants when we reach here. This is why the 256 colour and HiColour modes
  453.     should be the same resolution, perhaps i`ll make this an environment
  454.     variable
  455.  */
  456.  
  457.  
  458. void check_mi(void)
  459. {
  460.     if(mi!=0) return;
  461.  
  462.     if(DC==NULL) {
  463.         DC = SV_init( TRUE );
  464.     }
  465.  
  466.     if(modeNumber == 0 ) {
  467.         modeNumber = VESA_HICOLOUR_MODE;
  468.     }
  469.  
  470.     SV_getModeInfo(modeNumber,mi);
  471.  
  472.     return;
  473. }
  474.  
  475. int setup_vesa_mode(short height,short width,short depth)
  476. {
  477.     if(DC==NULL) {
  478.         DC = SV_init( TRUE );
  479.         /* how many bits per pixel */
  480.         if( depth == 0)
  481.             modeNumber = VESA_256COLOUR_MODE;
  482.         else
  483.             modeNumber = VESA_HICOLOUR_MODE;
  484.     }
  485.  
  486.     /* Check if correct VESA Version is available */
  487.     if( !DC || DC->VBEVersion < 0x0102) {
  488.         fprintf(stderr,"Require a VESA VBE version 1.2 or higher\n");
  489.         return FALSE;
  490.     }
  491.  
  492.     /* Check for LFB Supprt */
  493.     if(DC->VBEVersion < 0x0200 ) {
  494.         useLinear = FALSE;
  495.     } else {
  496.         useLinear = TRUE ;
  497.     }
  498.  
  499.      /* Get desired mode info */
  500.    if(!SV_getModeInfo( modeNumber, mi))
  501.         return FALSE;
  502.  
  503.     /* Set VESA mode */
  504.     if(!SV_setMode(modeNumber | svMultiBuffer, FALSE, TRUE, mi->NumberOfPages) )
  505.         return FALSE;
  506.  
  507.     return TRUE;
  508. }
  509.  
  510. void restore_video_mode(void)
  511. {
  512.     SV_restoreMode();
  513. }
  514.  
  515. void vga_clear(void)
  516. {
  517.     SV_clear(0);
  518. }
  519.  
  520. void vga_flip(void)
  521. {
  522.     activePage = 1-activePage;
  523.     visualPage = 1-activePage;
  524.  
  525.     SV_setActivePage(activePage);
  526.  
  527.     /*
  528.        Change false to true if you`re getting flickering
  529.        even in double buffer mode, ( sets wait for Vertical retrace  )
  530.     */
  531.     SV_setVisualPage(visualPage,false);
  532. }
  533.  
  534. int vga_getcolors(void)
  535. {
  536.     check_mi();
  537.     switch ( mi->BitsPerPixel ) {
  538.         case 8:
  539.             return 256;
  540.         case 15:
  541.         case 16:
  542.             return 32768;
  543.         default:
  544.             return 64000;
  545.      }
  546. }
  547.  
  548. int vga_getxdim(void)
  549. {
  550.     check_mi();
  551.     return mi->XResolution;
  552. }
  553.  
  554. int vga_getydim(void)
  555. {
  556.     check_mi();
  557.     return mi->YResolution;
  558. }
  559.  
  560. unsigned long current_color = 255;
  561.  
  562. void vga_setrgbcolor(int r,int g,int b)
  563. {
  564.     DOSMesa->red = r;
  565.     DOSMesa->green = g ;
  566.     DOSMesa->blue = b ;
  567.     current_color = SV_rgbColor(r,g,b);
  568. }
  569.  
  570. void vga_setcolor(int index)
  571. {
  572.     DOSMesa->index = index;
  573.     current_color = index;
  574. }
  575.  
  576. void vga_drawpixel(x,y)
  577. {
  578.     SV_putPixel(x,y,current_color);
  579. }
  580.  
  581. /* TODO: */
  582. int vga_getpixel(x,y)
  583. {
  584. /*    return (int)SV_getPixel(x,y); */
  585.     fprintf(stderr,"vga_getpixel: Not implemented yet\n");
  586.     return 1;
  587. }
  588.  
  589. /* End of UNIVBE section */
  590. #endif
  591.  
  592. /* Scitechs MegaGraphicsLibrary http://www.scitechsoft.com/ */
  593.  
  594. #if defined(MGL)
  595.  
  596. /* MGL support */
  597. struct MI {
  598.     unsigned short BitsPerPixel;
  599.     unsigned long XResolution;
  600.     unsigned long YResolution;
  601. };
  602.  
  603. struct MI*mi;
  604.  
  605. static MGLDC*DC;
  606. static int activePage = 0;
  607. static int visualPage = 1;
  608. static int modeNumber = 0;
  609.  
  610. void set_video_mode(unsigned short xres,unsigned short yres,char mode)
  611. {
  612.     int     i,driver = grDETECT,dmode = grDETECT;
  613.     event_t evt;
  614.  
  615.     /* Start the MGL with only the SVGA 16m driver active */
  616.     MGL_registerDriver(MGL_SVGA16NAME,SVGA16_driver);
  617.     if (!MGL_init(&driver,&dmode,"..\\..\\"))
  618.         MGL_fatalError(MGL_errorMsg(MGL_result()));
  619.     if ((DC = MGL_createDisplayDC(false)) == NULL)
  620.         MGL_fatalError(MGL_errorMsg(MGL_result()));
  621.     MGL_makeCurrentDC(DC);
  622. }
  623.  
  624. /*
  625.    This is problematic as we don`t know what resolution the user program
  626.    wants when we reach here. This is why the 256 colour and HiColour modes
  627.     should be the same resolution, perhaps i`ll make this an environment
  628.     variable
  629.  */
  630.  
  631. #define MGL_HICOLOUR_MODE 0
  632.  
  633.  
  634. void check_mi(void)
  635. {
  636.     if(mi!=0) return;
  637.  
  638.     if(DC==NULL) {
  639. //        DC = SV_init( TRUE );
  640.     }
  641.  
  642.     if(modeNumber == 0 ) {
  643.         modeNumber = MGL_HICOLOUR_MODE;
  644.     }
  645.  
  646. //    SV_getModeInfo(modeNumber,mi);
  647.  
  648.     return;
  649. }
  650.  
  651. void restore_video_mode(void)
  652. {
  653.     MGL_exit();
  654. }
  655.  
  656. void vga_clear(void)
  657. {
  658.     MGL_clearDevice();
  659. }
  660.  
  661. void vga_flip(void)
  662. {
  663.     activePage = 1-activePage;
  664.     visualPage = 1-activePage;
  665.  
  666. //    SV_setActivePage(activePage);
  667.  
  668.     /*
  669.        Change false to true if you`re getting flickering
  670.        even in double buffer mode, ( sets wait for Vertical retrace  )
  671.     */
  672. //    SV_setVisualPage(visualPage,false);
  673. }
  674.  
  675. int vga_getcolors(void)
  676. {
  677.     check_mi();
  678.     switch ( mi->BitsPerPixel ) {
  679.         case 8:
  680.             return 256;
  681.         case 15:
  682.         case 16:
  683.             return 32768;
  684.         default:
  685.             return 64000;
  686.      }
  687. }
  688.  
  689. int vga_getxdim(void)
  690. {
  691.     check_mi();
  692.     return mi->XResolution;
  693. }
  694.  
  695. int vga_getydim(void)
  696. {
  697.     check_mi();
  698.     return mi->YResolution;
  699. }
  700.  
  701. unsigned long current_color = 255;
  702.  
  703. void vga_setrgbcolor(int r,int g,int b)
  704. {
  705.     DOSMesa->red = r;
  706.     DOSMesa->green = g ;
  707.     DOSMesa->blue = b ;
  708.     current_color = MGL_rgbColor(DC,r,g,b);
  709. }
  710.  
  711. void vga_setcolor(int index)
  712. {
  713.     DOSMesa->index = index;
  714.     current_color = index;
  715. }
  716.  
  717. void vga_drawpixel(x,y)
  718. {
  719.     MGL_pixelCoord(x,y);
  720. }
  721.  
  722. /* TODO: */
  723. int vga_getpixel(x,y)
  724. {
  725. /*    return (int)SV_getPixel(x,y); */
  726.     fprintf(stderr,"vga_getpixel: Not implemented yet\n");
  727.     return 1;
  728. }
  729.  
  730. /* End of UNIVBE section */
  731. #endif
  732.  
  733. #ifdef GLIDE
  734.  
  735. /* GLIDE support */
  736.  
  737. static GrHwConfiguration hwconfig;
  738.  
  739. void set_video_mode(unsigned short x,unsigned short y,char mode)
  740. {
  741.     grGlideInit();
  742.     if( grSstQueryHardware( &hwconfig ) ) {
  743.         grSstSelect( 0 ) ;
  744.         if( !grSstOpen( GLIDE_MODE,
  745.                             GR_REFRESH_60Hz,
  746.                             GR_COLORFORMAT_ABGR,
  747.                             GR_ORIGIN_UPPER_LEFT,
  748.                             GR_SMOOTHING_ENABLE,
  749.                             2 ) ) {
  750.             fprintf(stderr,"Detected 3DFX board, but couldn`t initialize!");
  751.             exit(1);
  752.         }
  753.  
  754.         grBufferClear( 0, 0, GR_WDEPTHVALUE_FARTHEST);
  755.  
  756.         grDisableAllEffects();
  757.         atexit( glideshutdown );
  758.  
  759. //        guColorCombineFunction( GR_COLORCOMBINE_ITRGB );
  760. //        grTexCombineFunction( GR_TMU0, GR_TEXTURECOMBINE_ZERO);
  761.     }
  762. }
  763.  
  764. void restore_video_mode(void)
  765. {
  766. }
  767.  
  768. static void glideshutdown( void )
  769. {
  770.     grGlideShutdown() ;
  771. }
  772.  
  773. void vga_clear(void)
  774. {
  775.     grBufferSwap(0);
  776.     grBufferClear( 0, 0, GR_WDEPTHVALUE_FARTHEST);
  777. }
  778.  
  779. void vga_flip(void)
  780. {
  781. }
  782.  
  783. int vga_getcolors(void)
  784. {
  785.     return 32768;
  786. }
  787.  
  788. int vga_getxdim(void)
  789. {
  790. #if GLIDE_MODE == GR_RESOLUTION_800x600
  791.         return 800;
  792. #else
  793.         return 640;
  794. #endif
  795. }
  796.  
  797. int vga_getydim(void)
  798. {
  799. #if GLIDE_MODE == GR_RESOLUTION_800x600
  800.         return 600;
  801. #else
  802.         return 480;
  803. #endif
  804. }
  805.  
  806. unsigned long current_color = 255;
  807.  
  808. void vga_setrgbcolor(int r,int g,int b)
  809. {
  810.     DOSMesa->red = r;
  811.     DOSMesa->green = g ;
  812.     DOSMesa->blue = b ;
  813. }
  814.  
  815. void vga_setcolor(int index)
  816. {
  817.     DOSMesa->index = index;
  818. }
  819.  
  820. void vga_drawpixel(x,y)
  821. {
  822.  
  823.     gr_vtx.x = x;
  824.     gr_vtx.y = y;
  825.     gr_vtx.z = 0;
  826.     gr_vtx.r    = DOSMesa->red;
  827.     gr_vtx.g    = DOSMesa->green;
  828.     gr_vtx.b    = DOSMesa->blue;
  829.  
  830.     grDrawPoint( &gr_vtx );
  831. }
  832.  
  833. static void fast_tri(GLcontext *ctx,GLuint v0, GLuint v1, GLuint v2, GLuint pv )
  834. {
  835.    struct vertex_buffer *VB = ctx->VB;
  836.     GLuint shift = ctx->ColorShift  ;
  837.  
  838.     gr_vtx.z = 0;
  839.     gr_vtx1.z = 0;
  840.     gr_vtx2.z = 0;
  841.  
  842.    if (VB->MonoColor) {
  843.           gr_vtx.r = DOSMesa->red;
  844.        gr_vtx.g = DOSMesa->green;
  845.        gr_vtx.b = DOSMesa->blue;
  846.        gr_vtx1.r = DOSMesa->red;
  847.        gr_vtx1.g = DOSMesa->green;
  848.        gr_vtx1.b = DOSMesa->blue;
  849.        gr_vtx2.r = DOSMesa->red;
  850.        gr_vtx2.g = DOSMesa->green;
  851.        gr_vtx2.b = DOSMesa->blue;
  852.    } else {
  853.         if(ctx->Light.ShadeModel == GL_SMOOTH ) {
  854.               gr_vtx.r  = FixedToInt( VB->Color[v0][0] );
  855.               gr_vtx.g  = FixedToInt( VB->Color[v0][1] );
  856.               gr_vtx.b  = FixedToInt( VB->Color[v0][2] );
  857.  
  858.               gr_vtx1.r = FixedToInt( VB->Color[v1][0] );
  859.               gr_vtx1.g = FixedToInt( VB->Color[v1][1] );
  860.               gr_vtx1.b = FixedToInt( VB->Color[v1][2] );
  861.  
  862.               gr_vtx2.r = FixedToInt( VB->Color[v2][0] );
  863.               gr_vtx2.g = FixedToInt( VB->Color[v2][1] );
  864.               gr_vtx2.b = FixedToInt( VB->Color[v2][2] );
  865.         } else {
  866.               gr_vtx.r  = VB->Color[pv][0] >> shift ;
  867.               gr_vtx.g  = VB->Color[pv][1] >> shift ;
  868.               gr_vtx.b  = VB->Color[pv][2] >> shift ;
  869.  
  870.               gr_vtx1.r = VB->Color[pv][0] >> shift ;
  871.               gr_vtx1.g = VB->Color[pv][1] >> shift ;
  872.               gr_vtx1.b = VB->Color[pv][2] >> shift ;
  873.  
  874.               gr_vtx2.r = VB->Color[pv][0] >> shift ;
  875.               gr_vtx2.g = VB->Color[pv][1] >> shift ;
  876.               gr_vtx2.b = VB->Color[pv][2] >> shift ;
  877.         }
  878.     }
  879.  
  880.    gr_vtx.x  =       (VB->Win[v0][0] );
  881.    gr_vtx.y  = FLIP( (VB->Win[v0][1] ) );
  882.    gr_vtx1.x =       (VB->Win[v1][0] );
  883.    gr_vtx1.y = FLIP( (VB->Win[v1][1] ) );
  884.    gr_vtx2.x =       (VB->Win[v2][0] );
  885.    gr_vtx2.y = FLIP( (VB->Win[v2][1] ) );
  886.  
  887.     if(gr_vtx.x <0 || gr_vtx.x > 639 )
  888.         return;
  889.     if(gr_vtx1.x <0 || gr_vtx1.x > 639 )
  890.         return;
  891.     if(gr_vtx2.x <0 || gr_vtx2.x > 639 )
  892.         return;
  893.  
  894.     if(gr_vtx.y <0 || gr_vtx.y > 479 )
  895.         return;
  896.     if(gr_vtx1.y <0 || gr_vtx1.y > 479 )
  897.         return;
  898.     if(gr_vtx2.y <0 || gr_vtx2.y > 479 )
  899.         return;
  900.  
  901.     grDrawTriangle( &gr_vtx,&gr_vtx1,&gr_vtx2);
  902. }
  903.  
  904. void fast_plot(GLcontext *ctx,GLuint first,GLuint last )
  905. {
  906.     struct vertex_buffer *VB = ctx->VB;
  907.     register GLuint i;
  908.  
  909.     if(VB->MonoColor) {
  910.         /* all same color */
  911.  
  912.         gr_vtx.r = DOSMesa->red;
  913.         gr_vtx.g = DOSMesa->green;
  914.         gr_vtx.b = DOSMesa->blue;
  915.  
  916.         for(i=first;i<last;i++) {
  917.             if(VB->Unclipped[i]) {
  918.                 gr_vtx.x = VB->Win[i][0];
  919.                 gr_vtx.y = FLIP(VB->Win[i][1]);
  920.             }
  921.         }
  922.     }
  923. }
  924.  
  925. /* TODO: */
  926. int vga_getpixel(x,y)
  927. {
  928. /*    return (int)SV_getPixel(x,y); */
  929.     fprintf(stderr,"vga_getpixel: Not implemented yet\n");
  930.     return 1;
  931. }
  932.  
  933. /* End of GLIDE section */
  934.  
  935. #endif // GLIDE
  936. /**********************************************************************/
  937. /*****                 Miscellaneous functions                    *****/
  938. /**********************************************************************/
  939.  
  940.  
  941. static void get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
  942. {
  943.    *width = DOSMesa->width = vga_getxdim();
  944.    *height = DOSMesa->height = vga_getydim();
  945. }
  946.  
  947.  
  948. /* Set current color index */
  949. static void set_index( GLcontext *ctx, GLuint index )
  950. {
  951.    DOSMesa->index = index;
  952.    /*vga_setcolor( index );*/
  953. }
  954.  
  955.  
  956. /* Set current drawing color */
  957. static void set_color( GLcontext *ctx,
  958.                        GLubyte red, GLubyte green,
  959.                        GLubyte blue, GLubyte alpha )
  960. {
  961.    DOSMesa->red = red;
  962.    DOSMesa->green = green;
  963.    DOSMesa->blue = blue;
  964.    vga_setrgbcolor( red, green, blue );
  965. }
  966.  
  967.  
  968. static void clear_index( GLcontext *ctx, GLuint index )
  969. {
  970.    /* TODO: Implements glClearIndex() */
  971. }
  972.  
  973.  
  974. static void clear_color( GLcontext *ctx,
  975.                          GLubyte red, GLubyte green,
  976.                          GLubyte blue, GLubyte alpha )
  977. {
  978.    /* TODO: Implements glClearColor() */
  979. }
  980.  
  981.  
  982. static void clear( GLcontext *ctx,
  983.                    GLboolean all,
  984.                    GLint x, GLint y, GLint width, GLint height )
  985. {
  986.    vga_clear();
  987. }
  988.  
  989.  
  990. static GLboolean set_buffer( GLcontext *ctx,
  991.                              GLenum mode )
  992. {
  993.    /* TODO: implement double buffering and use this function to select */
  994.    /* between front and back buffers. */
  995.    return GL_TRUE;
  996. }
  997.  
  998.  
  999.  
  1000.  
  1001. /**********************************************************************/
  1002. /*****            Write spans of pixels                           *****/
  1003. /**********************************************************************/
  1004.  
  1005.  
  1006. static void write_index_span( GLcontext *ctx,
  1007.                               GLuint n, GLint x, GLint y,
  1008.                               const GLuint index[],
  1009.                               const GLubyte mask[] )
  1010. {
  1011.    int i;
  1012.    y = FLIP(y);
  1013. #ifdef UNIVBE
  1014.     SV_beginPixel();
  1015. #endif
  1016.    for (i=0;i<n;i++,x++) {
  1017.       if (mask[i]) {
  1018. #ifdef UNIVBE
  1019.         SV_putPixelFast(x,y,current_color);
  1020. #else
  1021.          vga_setcolor( index[i] );
  1022.          vga_drawpixel( x, y );
  1023. #endif
  1024.       }
  1025.    }
  1026.  
  1027. #ifdef UNIVBE
  1028.     SV_endPixel();
  1029. #endif
  1030.  
  1031. }
  1032.  
  1033.  
  1034.  
  1035. static void write_monoindex_span( GLcontext *ctx,
  1036.                                   GLuint n, GLint x, GLint y,
  1037.                                   const GLubyte mask[] )
  1038. {
  1039.    int i;
  1040.    y = FLIP(y);
  1041.    /* use current color index */
  1042.    vga_setcolor( DOSMesa->index );
  1043. #ifdef UNIVBE
  1044.     SV_beginPixel();
  1045. #endif
  1046.    for (i=0;i<n;i++,x++) {
  1047.       if (mask[i]) {
  1048. #ifdef UNIVBE
  1049.             SV_putPixelFast(x,y,current_color);
  1050. #else
  1051.          vga_drawpixel( x, y );
  1052. #endif
  1053.       }
  1054.    }
  1055. #ifdef UNIVBE
  1056.     SV_endPixel();
  1057. #endif
  1058. }
  1059.  
  1060.  
  1061.  
  1062. static void write_color_span( GLcontext *ctx,
  1063.                               GLuint n, GLint x, GLint y,
  1064.                               const GLubyte red[], const GLubyte green[],
  1065.                               const GLubyte blue[], const GLubyte alpha[],
  1066.                               const GLubyte mask[] )
  1067. {
  1068.    int i;
  1069.    y=FLIP(y);
  1070. #ifdef UNIVBE
  1071.     SV_beginPixel();
  1072. #endif
  1073.    if (mask) {
  1074.       /* draw some pixels */
  1075.       for (i=0; i<n; i++, x++) {
  1076.          if (mask[i]) {
  1077. #ifdef UNIVBE
  1078.                 SV_putPixelFast(x,y,SV_rgbColor(red[i], green[i], blue[i]) );
  1079. #else
  1080.             vga_setrgbcolor( red[i], green[i], blue[i] );
  1081.             vga_drawpixel( x, y );
  1082. #endif
  1083.          }
  1084.       }
  1085.    }
  1086.    else {
  1087.       /* draw all pixels */
  1088.       for (i=0; i<n; i++, x++) {
  1089. #ifdef UNIVBE
  1090.             SV_putPixelFast(x,y,SV_rgbColor(red[i], green[i], blue[i]) );
  1091. #else
  1092.          vga_setrgbcolor( red[i], green[i], blue[i] );
  1093.          vga_drawpixel( x, y );
  1094. #endif
  1095.       }
  1096.    }
  1097. #ifdef UNIVBE
  1098.     SV_endPixel();
  1099. #endif
  1100. }
  1101.  
  1102.  
  1103.  
  1104. static void write_monocolor_span( GLcontext *ctx,
  1105.                                   GLuint n, GLint x, GLint y,
  1106.                                   const GLubyte mask[])
  1107. {
  1108.    int i;
  1109.    y=FLIP(y);
  1110. #ifdef UNIVBE
  1111.     SV_beginPixel();
  1112. #endif
  1113.    /* use current rgb color */
  1114.    vga_setrgbcolor( DOSMesa->red, DOSMesa->green, DOSMesa->blue );
  1115.    for (i=0; i<n; i++, x++) {
  1116.       if (mask[i]) {
  1117. #ifdef UNIVBE
  1118.             SV_putPixelFast(x,y,current_color);
  1119. #else
  1120.          vga_drawpixel( x, y );
  1121. #endif
  1122.       }
  1123.    }
  1124. #ifdef UNIVBE
  1125.     SV_endPixel();
  1126. #endif
  1127. }
  1128.  
  1129.  
  1130.  
  1131. /**********************************************************************/
  1132. /*****                 Read spans of pixels                       *****/
  1133. /**********************************************************************/
  1134.  
  1135.  
  1136. static void read_index_span( GLcontext *ctx,
  1137.                              GLuint n, GLint x, GLint y, GLuint index[])
  1138. {
  1139.    int i;
  1140.    y = FLIP(y);
  1141.    for (i=0; i<n; i++,x++) {
  1142.       index[i] = vga_getpixel( x, y );
  1143.    }
  1144. }
  1145.  
  1146.  
  1147.  
  1148. static void read_color_span( GLcontext *ctx,
  1149.                              GLuint n, GLint x, GLint y,
  1150.                              GLubyte red[], GLubyte green[],
  1151.                              GLubyte blue[], GLubyte alpha[] )
  1152. {
  1153.    int i;
  1154.    for (i=0; i<n; i++, x++) {
  1155.       /* TODO */
  1156.    }
  1157. }
  1158.  
  1159.  
  1160.  
  1161. /**********************************************************************/
  1162. /*****                  Write arrays of pixels                    *****/
  1163. /**********************************************************************/
  1164.  
  1165.  
  1166. static void write_index_pixels( GLcontext *ctx,
  1167.                                 GLuint n, const GLint x[], const GLint y[],
  1168.                                 const GLuint index[], const GLubyte mask[] )
  1169. {
  1170.    int i;
  1171. #ifdef UNIVBE
  1172.     SV_beginPixel();
  1173. #endif
  1174.    for (i=0; i<n; i++) {
  1175.       if (mask[i]) {
  1176. #ifdef UNIVBE
  1177.             SV_putPixelFast(x[i], FLIP(y[i]), index[i] );
  1178. #else
  1179.          vga_setcolor( index[i] );
  1180.          vga_drawpixel( x[i], FLIP(y[i]) );
  1181. #endif
  1182.       }
  1183.    }
  1184. #ifdef UNIVBE
  1185.     SV_endPixel();
  1186. #endif
  1187. }
  1188.  
  1189.  
  1190.  
  1191. static void write_monoindex_pixels( GLcontext *ctx,
  1192.                                     GLuint n,
  1193.                                     const GLint x[], const GLint y[],
  1194.                                     const GLubyte mask[] )
  1195. {
  1196.    int i;
  1197.    /* use current color index */
  1198.    vga_setcolor( DOSMesa->index );
  1199. #ifdef UNIVBE
  1200.     SV_beginPixel();
  1201. #endif
  1202.    for (i=0; i<n; i++) {
  1203.       if (mask[i]) {
  1204. #ifdef UNIVBE
  1205.             SV_putPixelFast(x[i], FLIP(y[i]), DOSMesa->index);
  1206. #else
  1207.          vga_drawpixel( x[i], FLIP(y[i]) );
  1208. #endif
  1209.       }
  1210.    }
  1211. #ifdef UNIVBE
  1212.     SV_endPixel();
  1213. #endif
  1214. }
  1215.  
  1216.  
  1217.  
  1218. static void write_color_pixels( GLcontext *ctx,
  1219.                                 GLuint n, const GLint x[], const GLint y[],
  1220.                                 const GLubyte r[], const GLubyte g[],
  1221.                                 const GLubyte b[], const GLubyte a[],
  1222.                                 const GLubyte mask[] )
  1223. {
  1224.    int i;
  1225. #ifdef UNIVBE
  1226.     SV_beginPixel();
  1227. #endif
  1228.    for (i=0; i<n; i++) {
  1229.       if (mask[i]) {
  1230. #ifdef UNIVBE
  1231.             SV_putPixelFast(x[i], FLIP(y[i]), SV_rgbColor(r[i], g[i], b[i]) );
  1232. #else
  1233.          vga_setrgbcolor( r[i], g[i], b[i] );
  1234.          vga_drawpixel( x[i], FLIP(y[i]) );
  1235. #endif
  1236.       }
  1237.    }
  1238. #ifdef UNIVBE
  1239.     SV_endPixel();
  1240. #endif
  1241. }
  1242.  
  1243. static void write_monocolor_pixels( GLcontext *ctx,
  1244.                                     GLuint n,
  1245.                                     const GLint x[], const GLint y[],
  1246.                                     const GLubyte mask[] )
  1247. {
  1248.    int i;
  1249.    /* use current rgb color */
  1250.    vga_setrgbcolor( DOSMesa->red, DOSMesa->green, DOSMesa->blue );
  1251. #ifdef UNIVBE
  1252.     SV_beginPixel();
  1253. #endif
  1254.    for (i=0; i<n; i++) {
  1255.       if (mask[i]) {
  1256. #ifdef UNIVBE
  1257.             SV_putPixelFast(x[i], FLIP(y[i]), current_color );
  1258. #else
  1259.          vga_drawpixel( x[i], FLIP(y[i]) );
  1260. #endif
  1261.       }
  1262.    }
  1263. #ifdef UNIVBE
  1264.     SV_endPixel();
  1265. #endif
  1266. }
  1267.  
  1268. /**********************************************************************/
  1269. /*****                   Read arrays of pixels                    *****/
  1270. /**********************************************************************/
  1271.  
  1272. /* Read an array of color index pixels. */
  1273. static void read_index_pixels( GLcontext *ctx,
  1274.                                GLuint n, const GLint x[], const GLint y[],
  1275.                                GLuint index[], const GLubyte mask[] )
  1276. {
  1277.    int i;
  1278.    for (i=0; i<n; i++) {
  1279.       index[i] = vga_getpixel( x[i], FLIP(y[i]) );
  1280.    }
  1281. }
  1282.  
  1283.  
  1284.  
  1285. static void read_color_pixels( GLcontext *ctx,
  1286.                                GLuint n, const GLint x[], const GLint y[],
  1287.                                GLubyte red[], GLubyte green[],
  1288.                                GLubyte blue[], GLubyte alpha[],
  1289.                                const GLubyte mask[] )
  1290. {
  1291.    /* TODO */
  1292. }
  1293.  
  1294. static void DOSmesa_setup_DD_pointers( GLcontext *ctx )
  1295. {
  1296.    /* Initialize all the pointers in the DD struct.  Do this whenever */
  1297.    /* a new context is made current or we change buffers via set_buffer! */
  1298.  
  1299.    ctx->Driver.UpdateState = DOSmesa_setup_DD_pointers;
  1300.  
  1301.    ctx->Driver.ClearIndex = clear_index;
  1302.    ctx->Driver.ClearColor = clear_color;
  1303.    ctx->Driver.Clear = clear;
  1304.  
  1305.    ctx->Driver.Index = set_index;
  1306.    ctx->Driver.Color = set_color;
  1307.  
  1308.    ctx->Driver.SetBuffer = set_buffer;
  1309.    ctx->Driver.GetBufferSize = get_buffer_size;
  1310.  
  1311.    ctx->Driver.PointsFunc = choose_points_function();
  1312.    ctx->Driver.LineFunc = choose_line_function();
  1313.    ctx->Driver.TriangleFunc = choose_triangle_function();
  1314.  
  1315.  
  1316.    /* Pixel/span writing functions: */
  1317.    /* TODO: use different funcs for 8, 16, 32-bit depths */
  1318.    ctx->Driver.WriteColorSpan       = write_color_span;
  1319.    ctx->Driver.WriteMonocolorSpan   = write_monocolor_span;
  1320.    ctx->Driver.WriteColorPixels     = write_color_pixels;
  1321.    ctx->Driver.WriteMonocolorPixels = write_monocolor_pixels;
  1322.    ctx->Driver.WriteIndexSpan       = write_index_span;
  1323.    ctx->Driver.WriteMonoindexSpan   = write_monoindex_span;
  1324.    ctx->Driver.WriteIndexPixels     = write_index_pixels;
  1325.    ctx->Driver.WriteMonoindexPixels = write_monoindex_pixels;
  1326.  
  1327.    /* Pixel/span reading functions: */
  1328.    /* TODO: use different funcs for 8, 16, 32-bit depths */
  1329.    ctx->Driver.ReadIndexSpan = read_index_span;
  1330.    ctx->Driver.ReadColorSpan = read_color_span;
  1331.    ctx->Driver.ReadIndexPixels = read_index_pixels;
  1332.    ctx->Driver.ReadColorPixels = read_color_pixels;
  1333. }
  1334.  
  1335. /*
  1336.  * Create a new VGA/Mesa context and return a handle to it.
  1337.  */
  1338. DOSMesaContext DOSMesaCreateContext( void )
  1339. {
  1340.    DOSMesaContext ctx;
  1341.    GLboolean rgb_flag;
  1342.    GLfloat redscale, greenscale, bluescale, alphascale;
  1343.    GLboolean db_flag = GL_FALSE;
  1344.    GLboolean alpha_flag = GL_FALSE;
  1345.    int colors;
  1346.    GLint index_bits;
  1347.  
  1348. #if !defined(UNIVBE) && !defined(GLIDE) && !defined(MGL)
  1349.     video_buffer = (unsigned char *) malloc( vga_getxdim() * vga_getydim() );
  1350.  
  1351.     memset(video_buffer,0, vga_getxdim() * vga_getydim() );
  1352.  
  1353.     memset(rgbtable,0,sizeof( rgbtable ) );
  1354. #endif
  1355.  
  1356. #if defined( DJGPP ) && !defined(UNIVBE) && !defined(GLIDE)
  1357.     dos_seg = _go32_conventional_mem_selector();
  1358. #endif
  1359.  
  1360.    /* determine if we're in RGB or color index mode */
  1361.    colors = vga_getcolors();
  1362.    if (colors==32768) {
  1363.       rgb_flag = GL_TRUE;
  1364.       redscale = greenscale = bluescale = alphascale = 255.0;
  1365.       index_bits = 0;
  1366.    }
  1367.    else if (colors==256) {
  1368.       rgb_flag = GL_FALSE;
  1369.       redscale = greenscale = bluescale = alphascale = 0.0;
  1370.       index_bits = 8;
  1371.    }
  1372.    else {
  1373.         restore_video_mode();
  1374.       fprintf(stderr,"[%d] >16 bit color not implemented yet!\n",colors);
  1375.       return NULL;
  1376.    }
  1377.  
  1378.    ctx = (DOSMesaContext) calloc( 1, sizeof(struct DOSmesa_context) );
  1379.    if (!ctx) {
  1380.       return NULL;
  1381.    }
  1382.  
  1383.    ctx->gl_vis = gl_create_visual( rgb_flag,
  1384.                                    alpha_flag,
  1385.                                    db_flag,
  1386.                                    16,   /* depth_size */
  1387.                                    8,    /* stencil_size */
  1388.                                    16,   /* accum_size */
  1389.                                    index_bits,
  1390.                                    redscale,
  1391.                                    greenscale,
  1392.                                    bluescale,
  1393.                                    alphascale );
  1394.  
  1395.    ctx->gl_ctx = gl_create_context( ctx->gl_vis,
  1396.                                     NULL,  /* share list context */
  1397.                                     (void *) ctx
  1398.                                   );
  1399.  
  1400.    ctx->gl_buffer = gl_create_framebuffer( ctx->gl_vis );
  1401.  
  1402.    ctx->index = 1;
  1403.    ctx->red = ctx->green = ctx->blue = 255;
  1404.  
  1405.    ctx->width = ctx->height = 0;  /* temporary until first "make-current" */
  1406.  
  1407.    return ctx;
  1408. }
  1409.  
  1410. /*
  1411.  * Destroy the given VGA/Mesa context.
  1412.  */
  1413. void DOSMesaDestroyContext( DOSMesaContext ctx )
  1414. {
  1415.    if (ctx) {
  1416.       gl_destroy_visual( ctx->gl_vis );
  1417.       gl_destroy_context( ctx->gl_ctx );
  1418.       gl_destroy_framebuffer( ctx->gl_buffer );
  1419.       free( ctx );
  1420.       if (ctx==DOSMesa) {
  1421.          DOSMesa = NULL;
  1422.       }
  1423.    }
  1424. }
  1425.  
  1426.  
  1427.  
  1428. /*
  1429.  * Make the specified VGA/Mesa context the current one.
  1430.  */
  1431. void DOSMesaMakeCurrent( DOSMesaContext ctx )
  1432. {
  1433.    DOSMesa = ctx;
  1434.    gl_make_current( ctx->gl_ctx, ctx->gl_buffer );
  1435.    DOSmesa_setup_DD_pointers( ctx->gl_ctx );
  1436.  
  1437.    if (ctx->width==0 || ctx->height==0) {
  1438.       /* setup initial viewport */
  1439.       ctx->width = vga_getxdim();
  1440.       ctx->height = vga_getydim();
  1441.       gl_Viewport( ctx->gl_ctx, 0, 0, ctx->width, ctx->height );
  1442.    }
  1443. }
  1444.  
  1445.  
  1446.  
  1447. /*
  1448.  * Return a handle to the current VGA/Mesa context.
  1449.  */
  1450. DOSMesaContext DOSMesaGetCurrentContext( void )
  1451. {
  1452.    return DOSMesa;
  1453. }
  1454.  
  1455.  
  1456. /*
  1457.  * Swap front/back buffers for current context if double buffered.
  1458.  */
  1459. void DOSMesaSwapBuffers( void )
  1460. {
  1461. #if !defined(UNIVBE)
  1462. /* Assume double buffering is available if in UNIVBE,
  1463.    if it isn`t its taken care of anyway */
  1464. //   if (DOSMesa->gl_vis->DBflag)
  1465. #endif
  1466.      {
  1467.       vga_flip();
  1468.    }
  1469. }
  1470.  
  1471.  
  1472. #else
  1473.  
  1474. /*
  1475.  * Need this to provide at least one external definition when DOS is
  1476.  * not defined on the compiler command line.
  1477.  */
  1478.  
  1479. int gl_DOS_dummy_function(void)
  1480. {
  1481.    return 0;
  1482. }
  1483.  
  1484. #endif  /*DOS*/
  1485.  
  1486.